package com.wanxi;

import com.wanxi.model.StudentModel;

import java.util.ArrayList;

public class FilterArray {
    public static void main(String[] args) {
        /**
         * 1.定义一个集合对象：增加元素
         * 2.判断年龄是否低于18
         * 3.打印新的集合
         */
        ArrayList<StudentModel> studentModelArrayList=new ArrayList<>();
        studentModelArrayList.add(new StudentModel("a",19));
        studentModelArrayList.add(new StudentModel("a",20));
        studentModelArrayList.add(new StudentModel("a",15));
        studentModelArrayList.add(new StudentModel("a",17));
        ArrayList<StudentModel> filter = filter(studentModelArrayList);
        System.out.println(filter);
    }
    private static ArrayList<StudentModel> filter(ArrayList<StudentModel> studentModelArrayList){
        ArrayList<StudentModel> list=new ArrayList<>();
        for (int i = 0; i < studentModelArrayList.size(); i++) {
            if(studentModelArrayList.get(i).getAge()<18){
                list.add(studentModelArrayList.get(i));
            }
        }
        return list;
    }
}
